<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>


<style>
#attachments {text-align:center;border:1px solid #ddd; border-width:0 0 1px 1px;}

#attachments th {background:#CCEEFF;}
#attachments th,#attachments td {height:22px; border:1px solid #ddd; border-width:1px 1px 0 0;}
</style>


<script type="text/javascript">
<!--
	function deleteAttach(attachId){
		window.location.href = "./AttachmentMgr_delete.do?attachmentId="+attachId+"&saId="+$("#saId").val();
	}
	
	function showAttach(attachId){
	    var location = "./AttachmentMgr_show.do?attachmentId="+attachId;
		window.open(location,'','width=790,height=590');
	}
	
	function onSave(){
		  var errorMsg = "";
			if($("#relativeStatus").val().trim()=="" || $("#upload").val().trim()=="" || $("#category_id").val().trim()=="" ){
				errorMsg = '<s:text name="dialog.message.tip.needRequiredFields"/>' ;
			}
			if(errorMsg != ""){
				showErrorTip(errorMsg);
				return false;
			}
			return true;
	}
	
	function editSa(saId){
		window.location.href = "./SaMgr_editSa.do?editSaId="+saId;
	}
	
//-->
</script>

<s:include value="./component/tip_box.jsp"></s:include>
<div style="background-color:#F5F5F5;margin-top:1cm;">
	<s:form action="AttachmentMgr_upload" validate="false" method="post" enctype="multipart/form-data" onsubmit="return onSave()">
		<s:hidden id="saId" key="attachment.saId"/>
		
		<div align="left">
			<s:actionmessage cssStyle="color:#0000FF;"/>
			<s:actionerror cssStyle="color:#F00;"/>
		</div>
		<table width="100%" height="60" >
			<tr>
				<td align="right" width="15%">
				   <s:text name="attachment.relativeStatus"/><font color="red">*</font>:
				</td>
				<td align="left"  width="5%">
				  <s:select id="relativeStatus" name="attachment.relativeStatus" list="usableStates" cssStyle="width: 50px; "/>
				</td>
				
				<td align="right" width="10%">
				   <s:text name="attachment.category"/><font color="red">*</font>:
				</td>
				<td align="left"  width="10%">
				  <s:select id="category_id" name="attachment.category_id" list="categorys"/>
				</td>
				
				<td align="right"  width="10%">
					<s:text name="attachment.file"/><font color="red">*</font>:
				</td>
				<td align="left" width="20%">
					<s:file key="upload" id="upload"></s:file>
				</td>
				<td align="left" width="20%">
					<s:submit cssClass="btn" key="action.add" action="AttachmentMgr_upload"/>
					<input class="btn" type="button" value="<s:text name="action.return"/>" onclick="editSa('${attachment.saId}')">
				</td>
			</tr>
		</table>
	</s:form>
	
	<table width="100%" id="attachments" >
		<thead>
			<tr class="ui-widget-header">
				<th style="width: 20em;"><s:text name="attachment.relativeStatus"/></th>
				<th style="width: 20em;"><s:text name="attachment.category"/></th>
				<th style="width: 20em;"><s:text name="attachment.file"/></th>
				<th style="width: 10em;" colspan="1"><s:text name="action.action"/></th>
			</tr>
		</thead>
		<tbody>
			<c:if test="${empty saAttachments}">
			   <tr>
				   	<td colspan="3" align="center">
						<font color="red"><s:text name="message.search.nodata"/></font>
				   	</td>
			   </tr>
			</c:if>
			<c:forEach var="each" items="${saAttachments}">
				<tr>
					<td>${each.relativeStatusShow}</td>
					<td>${each.category.cateName}</td>
					<td>${each.fileName}</td>
					<td>
						<input class="btn" type="button" value="<s:text name="action.view"/>" onclick="showAttach('${each.id}')">
						<input class="btn" type="button" value="<s:text name="action.delete"/>" onclick="deleteAttach('${each.id}')">
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</div>